Start: 'Cellualar Automata 'By Flynn D. Fishman 'January 1985 'Feel Free to copy this program and give it to friends ON ERROR GOTO Bug ERROR ON size=320 SCREEN 2,size,200,5,1 WINDOW 2,"Automata",(0,0)-(297,185),1,2 PALETTE 0,0,0,0 PALETTE 1,1,0,0 PALETTE 2,0,1,0 PALETTE 3,0,0,1 PALETTE 4,1,0.75,0 PALETTE 5,1,0,0.75 PALETTE 6,0,0.75,1 PALETTE 7,1,1,1 PALETTE 8,0.5,1,0.5 PALETTE 9,1,0.5,0.5 PALETTE 31,0,1,1 PALETTE 30,0.5,0.1,0.2 COLOR 2 PRINT"Cellular Automata" COLOR 7 PRINT"By Flynn D. Fishman" COLOR 4 PRINT"Courtesy PRINT"Of Phase 4 Distributors Inc. Canada PRINT COLOR 5 PRINT "Please Wait Loading Sprite's" OPEN "Top.spr" FOR INPUT AS 1 OBJECT.SHAPE 1,INPUT$(LOF(1),1) CLOSE 1 OPEN "Bottom.spr" FOR INPUT AS 1 OBJECT.SHAPE 2,INPUT$(LOF(1),1) CLOSE 1 WINDOW 3,"Data",(3,3)-(150,19),,2 WINDOW OUTPUT 2 size=300 CLS LOCATE 5,1 COLOR 7 PRINT"Did You Want An Explanation?" a$="" WHILE a$="" a$=INKEY$ WEND IF a$="y" OR a$="Y" THEN GOSUB explanation DIM rule(100),li%(90) LINE (2,165)-(2,175),11 PSET (2,170),0 GET (2,165)-(2,175),li% PUT (2,165),li% Set.Defaults: rule$="101" PSET (size/2,170),1 xorigion=size/2-4 yorigion=160 GOSUB Set.Behaviour y=171 GOSUB Set.Up.First.Generation MENU 1,0,1,"Alterations" MENU 1,1,1,"Change Rules " MENU 1,2,1,"Edit Current Generation" MENU 1,3,1,"Reset Program " MENU 1,4,1,"Pause Program " MENU 1,5,1,"Color Table " MENU 1,6,1,"Turn Zoom On " MENU 1,7,1,"Explanation " MENU 1,8,1,"Exit to System " FOR m=2 TO 4 MENU m,0,1,"" NEXT LOCATE 10,1 PRINT "Use The Pull Down Menus To" PRINT "See The options" ON MENU GOSUB Change: MENU ON Initialize: generation=1 WINDOW OUTPUT 3 LOCATE 1,1 COLOR 5 PRINT"Life System:";rule$ COLOR 6 PRINT"Generation :";generation; WINDOW OUTPUT 2 Life.Loop: FOR y=171 TO 178 living=0 LINE (1,y)-(size,y),10 FOR x=1 TO size cell=rule(POINT(x-1,y-1)+POINT(x,y-1)+POINT(x+1,y-1)) living=living+cell PSET (x,y),cell NEXT x generation=generation+1 WINDOW OUTPUT 3 LOCATE 1,1 COLOR 5 PRINT"Life System:";rule$ COLOR 6 PRINT"Generation :";generation; WINDOW OUTPUT 2 IF living=0 THEN WHILE 1=1 FOR i=1 TO 31 COLOR i LOCATE 4,1 PRINT "This system died on Generation"generation NEXT WEND END IF NEXT y LOCATE 25,1 PRINT IF Zoom=1 THEN GOSUB Update.Zoom GOTO Life.Loop Change: ON MENU(1) GOSUB Set.Behaviour,Set.Up.First.Generation,Start.Over,Pause,Color.Table,Toggle.Zoom,explanation,Bye RETURN Set.Behaviour: WINDOW 5,"Try These",(10,50)-(290,106),,2 COLOR 4 PRINT"Try These" COLOR 5 PRINT"22133105 42004105 331240 PRINT"202432105 33111003204 12011203 COLOR 4 PRINT"Try These with a Random Generation COLOR 5 PRINT"11004005 22310005 131205 PRINT"32113105 WINDOW 4,"Please Enter Rule:",(3,3)-(180,19),,2 LOCATE 1,1 COLOR 2 PRINT " "rule$; LOCATE 1,1 INPUT a$ IF a$="" THEN a$=rule$ rule$=a$ WINDOW CLOSE 5 WINDOW CLOSE 4 FOR i=LEN(rule$)-1 TO 1 STEP -1 rule(LEN(rule$)-i-1)=VAL(MID$(rule$,i,1)) NEXT RETURN Set.Up.First.Generation: WINDOW 5,"Instructions",(1,1)-(290,60),1,2 COLOR 4 PRINT "Set Up The First Generation" COLOR 3 PRINT "Move Indicator with the Mouse" PRINT "-Left Button or Return when Finished" PRINT "-Any Number To Define That cell" PRINT "-C to Clear the Line PRINT "-R to set up a Random Generation" WINDOW OUTPUT 2 last=MOUSE(1) PUT (last,y-6),li% Define.Start: IF MOUSE(1)<>last THEN PUT (last,y-6),li% last=MOUSE(1) PUT (last,y-6),li% END IF a$=INKEY$ IF a$="C" OR a$="c" THEN LINE (0,y-1)-(size,y-1),0 IF a$=>"0" AND a$<="9" THEN PSET (last,y-1),VAL(a$) IF a$="r" OR a$="R" THEN max=0 FOR i=1 TO LEN(rule$) IF VAL(MID$(rule$,i,1))>max THEN max=VAL(MID$(rule$,i,1)) NEXT i FOR i=1 TO size PSET (i,y-1),INT(RND(2)*max+0.5) NEXT i END IF IF a$<>CHR$(13) AND MOUSE(0)<>-1 THEN Define.Start PUT (last,y-6),li% WINDOW CLOSE 5 RETURN Start.Over: RUN Bye: SYSTEM Pause: WINDOW 4,"Pause On",(0,0)-(260,10) PRINT "Press The Mouse Button To UnPause"; WHILE MOUSE(0)<>-1 'Do Nothing WEND WINDOW CLOSE 4 RETURN Color.Table: WINDOW 4,"Color Table",(0,0)-(280,10) FOR x=1 TO 9 COLOR 0,x PRINT" "; COLOR x,0 PRINT"-";RIGHT$(STR$(x),1);" "; NEXT WHILE MOUSE(0)<>-1 'Do Nothing WEND WINDOW CLOSE 4 RETURN Bug: 'do nothing RESUME NEXT Toggle.Zoom: IF Zoom=1 THEN Zoom=0 WINDOW OUTPUT 2 WINDOW CLOSE 4 OBJECT.OFF 1,2 MOUSE OFF MENU 1,6,1,"Turn Zoom On " ELSE Zoom=1 OBJECT.ON 1,2 WINDOW 4,"Zoom",(2,2)-(100,100) GOSUB Update.Zoom ON MOUSE GOSUB Move.Zoom.Window MOUSE ON MENU 1,6,1,"Turn Zoom Off " END IF RETURN Update.Zoom: WINDOW OUTPUT 4 LOCATE 1,1 xaccross=INT(WINDOW(2)/8)-1 yaccross=INT(WINDOW(3)/8)-1 WINDOW OUTPUT 2 OBJECT.X 1,xorigion-3 OBJECT.Y 1,yorigion+6 OBJECT.X 2,xorigion+xaccross-6 OBJECT.Y 2,yorigion+yaccross-1 FOR yzoom=1 TO yaccross FOR xzoom = 1 TO xaccross WINDOW OUTPUT 2 Col=POINT (xzoom+xorigion,yzoom+yorigion) ' PSET (xzoom+xorigion,yzoom+yorigion),15 WINDOW OUTPUT 4 COLOR Col PRINT "*"; NEXT xzoom PRINT NEXT yzoom WINDOW OUTPUT 2 RETURN Move.Zoom.Window: WINDOW OUTPUT 4 xaccross=INT(WINDOW(2)/8)-1 yaccross=INT(WINDOW(3)/8)-1 WINDOW OUTPUT 2 WHILE MOUSE (0)=-1 xorigion=MOUSE(1) yorigion=MOUSE(2) OBJECT.X 1,xorigion-3 OBJECT.Y 1,yorigion+6 OBJECT.X 2,xorigion+xaccross-6 OBJECT.Y 2,yorigion+yaccross-1 WEND GOSUB Update.Zoom RETURN explanation: WINDOW OUTPUT 2 WINDOW 5,"Explanation",(0,0)-(297,48),,2 DATA"Cellular Automata is a branch of DATA"'Mathematics' where a 'Life System' DATA"Is given a set of rules in DATA"Numerical form from which that system DATA"Should exist by. DATA"I obtained most of my information DATA"For this science from an article DATA"By Stephen Wolfram (a major force in DATA"Mathematical Computer Simulations DATA"Including Automata) I believe that DATA"The article was in a 1985 issue of DATA"Scientific America page 188-203 DATA"'Computer Software in Science and DATA"Mathematics'. I am sorry that I can DATA"Not be more specific on the date. DATA"In a Cellular Automata the history DATA"Of a life system scrolls up the DATA"Screen. Each cell is represented DATA"By a colored dot. The color of the DATA"Dot represents the density of that DATA"Area of the life system. The density DATA"Of a cell is calculated by the sum DATA"Of the density of the two neighboring DATA"Cells and the current cell. It is DATA"Then displayed on the line directly DATA"Underneath the current generation. DATA"The rules for the system is based DATA"On a numerical digit comprised of DATA"Several digits from 0 to 9. The DATA"Far right number represents the number DATA"System you are working with. For DATA"Example if the last number is 3 DATA"Then you will not have a density DATA"Higher than that number. DATA"The other digits in the rule represents DATA"The density of a particular DATA"Cell working right to left. For DATA"Example when working with the DATA"'3104' the number system is 4. If DATA"The sum of a cells neighbours is 0 DATA"Then that cell has a density of 0. DATA"If the neighbours' sum is 1 then the DATA"Density of that cell would be 1. DATA"And if the sum=2 then the density=3 DATA"Note that when zoom is on you can DATA"Move the zoom window by pointing to DATA"Arrow at the new location and DATA"The left button" DATA"" DATA"Please Click The Mouse to Continue" DATA"end" LOCATE 1,1 COLOR 2 PRINT"To Pause the Explanation PRINT"Click the RIGHT button" COLOR 3 PRINT"Click the Left Button To Begin" WHILE MOUSE(0)<>-1 'Do Nothing WEND COLOR 4 RESTORE READ da$ WHILE da$<>"end" LOCATE 6,1 PRINT da$; READ da$ FOR sc= 1 TO 8 SCROLL (0,0)-(320,48),0,-1 NEXT sc WEND WHILE MOUSE(0)<>-1 'Do Nothing WEND IF Zoom=1 THEN MOUSE ON WINDOW OUTPUT 2 WINDOW CLOSE 5 RETURN